package construction.proxy.cglib;


//import net.sf.cglib.construction.proxy.Enhancer;
//import net.sf.cglib.construction.proxy.MethodInterceptor;
//import net.sf.cglib.construction.proxy.MethodProxy;

//public class ProxyFactory implements MethodInterceptor {
//    private TeacherDao target;
//
//    public ProxyFactory(TeacherDao target) {
//        this.target = target;
//    }
//
//    @Override
//    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
//        return method.invoke(target,objects);
//    }
//
//    public Object getProxyInstance(){
//        //1.创建一个工具类
//        Enhancer enhancer = new Enhancer();
//        //2.设置父类
//        enhancer.setSuperclass(target.getClass());
//        //3.设置回调函数
//        enhancer.setCallback(this);
//        //4.创建子类对象 即代理对象
//        return enhancer.create();
//
//    }


//    Object getProxyInstance(ITeacherDao target){
//
//        //Object newProxyInstance(ClassLoader loader,Class<?>[] interfaces,InvocationHandler h)
//        var obj = Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(),
//                new InvocationHandler() {
//                    @Override
//                    public Object invoke(Object construction.proxy, Method method, Object[] args) throws Throwable {
//                        return method.invoke(target,args);
//                    }
//                }
//        );
//        return obj;
//    }

//}
